using System;
using MDAControlsFramework;
using MDAControlsFramework.Helpers;

namespace MDACalendar {
	public class ControlDayList: MDAContainer {
		private DateTime _date;

		public DateTime Date {
			get {
				return _date;
			}
			set {
				this.DataChange(this, new MDADataChangeArgs(_date, value));
				_date = value;
			}
		}

		public override void Initialize() {
			if (_name == string.Empty) {
				_name = "DayList";
			}
			base.Initialize();
			this.Date = DateTime.Now;
			SetMouseEvent("OnMouseSlideHorizontal", MoveNextDay);
		}

		public override MDAMouseEventHandler MouseEventFactory(string name) {
			if (name == "movenext") {
				return this.MoveNextDay;
			}

			return null;
		}

		public void MoveNextDay(object sender, MDAMouseEventArgs e) {
			int difX = e.ActualPoint.X - e.FirstPoint.X;
			_animation.PrepareAnimation(this);

			if (difX < 0) {
				this.MoveNextDay();
				_animation.AnimType = AnimationTypesEnum.rightToLeft;
			} else {
				this.MovePreviousDay();
				_animation.AnimType = AnimationTypesEnum.leftToRight;
			}
			this.InvalidateGraphics();
			_animation.StartAnimate(this);
		}

		public void MoveNextDay() {
			this.Date = _date.AddDays(1);
		}

		public void MovePreviousDay() {
			this.Date = _date.AddDays(-1);
		}
	}
}
